package com.jason.www.code;


import com.jason.www.enums.PayType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
public class PayClientFactory {

    @Autowired
    private Map<String, IPayClient> payClientMap;


    public IPayClient getPayClient(PayType payType) {
        Optional.ofNullable(payType.getClient()).orElseThrow(()-> new RuntimeException("支付客户端不能为空"));
        return getPayClient(payType.getCode());
    }

    public IPayClient getPayClient(Byte payType) {
        return payClientMap.get(PayType.getPayType(payType).getClient());
    }

}
